#include "LogicAndNode.h"
#include "..\Common\AssertHelper.h"

using namespace std;

namespace CExpression
{
	void LogicAndNode::Eval(ExecuteContext &context)
	{
		this->left->Eval(context);
		if(AssertHelper::ExpectType(context.TempResultType(),ExecuteRunTimeType::Double,context,TEXT("Logic-and operator's operand must be double type.")))
		{
			int operand1=static_cast<int>(context.GlobalTempNum());
			this->right->Eval(context);
			if(AssertHelper::ExpectType(context.TempResultType(),ExecuteRunTimeType::Double,context,TEXT("Logic-and operator's operand must be double type.")))
			{
				context.SetGlobalTempNum(operand1&static_cast<int>(context.GlobalTempNum()));
				context.SetTempResultType(ExecuteRunTimeType::Double);
			}
		}
	}

	shared_ptr<Node> LogicAndNode::Clone(Expression &parent)
	{
		shared_ptr<Node> result(new LogicAndNode(this->left->Clone(parent),this->right->Clone(parent)));
		return result;
	}
}